import request from '@/utils/request';

type TableInfoForm = {
  id?: number;
  name: string;
  code: string;
  sort: number;
  statisticalRange: string;
  submittedUnit: string;
  submittedDate: string;
};

function genFunc(name) {
  return {
    getAll(params) {
      return request.get(`/kjtjdc/${name}/list`, {
        params: {
          deptName: params.deptName,
          years: params.years,
          approveStatus: params.approveStatus,
          pageSize: params.pageSize,
          pageNum: params.pageNum
        },
      });
    },
    getMy(years) {
      return request.get(`/kjtjdc/${name}/myList`, { params: { years } });
    },
    add(data) {
      return request.post(`/kjtjdc/${name}/add`, data);
    },
    edit(data) {
      return request.post(`/kjtjdc/${name}/update`, data);
    },
    del(id) {
      return request.post(`/kjtjdc/${name}/delete/${id}`);
    },
    getInfoById(id) {
      return request.get(`/kjtjdc/${name}/detail/${id}`);
    },
  }
}

const table = {
  getTableList() {
    return request.get('/kjtjdc/tableInfo/list');
  },
  addTable(data: TableInfoForm) {
    return request.post('/kjtjdc/tableInfo/add', data);
  },
  updateTableInfo(data: TableInfoForm) {
    return request.post('/kjtjdc/tableInfo/update', data);
  },
  deleteTableInfo(id: number) {
    return request.post(`/kjtjdc/tableInfo/delete/${id}`);
  },
  getTableInfoById(id: number) {
    return request.get(`/kjtjdc/tableInfo/detail/${id}`);
  },
  getMyTables(years) {
    return request.get('/kjtjdc/tableUnit/myTableList', { params: { years } });
  },
  // 基本信息
  unitInfo: {
    ...genFunc('unitInfo')
  },
  // 人员规模
  personInfo: {
    ...genFunc('personInfo')
  },
  // 科研条件
  researchCondition: {
    ...genFunc('researchCondition')
  },
  // 研发经费开支
  devFundingSpend: {
    ...genFunc('devFundingSpend')
  },
  // 科技项目信息
  projectInfo: {
    ...genFunc('projectInfo')
  },
  // 科技成果信息
  resultInfo: {
    ...genFunc('resultInfo')
  },
  // 国际科技合作与交流
  cooperationInfo: {
    ...genFunc('cooperationInfo')
  },
  // 交通运输行业重点实验室
  labInfo: {
    ...genFunc('labInfo')
  },
  // 标准化情况
  standardizedInfo: {
    ...genFunc('standardizedInfo')
  },
};
export default table;
